package com.atstudent.gmall.search.rpc;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.search.biz.GoodsBizService;
import com.atstudent.gmall.search.dto.SearchParamDTO;
import com.atstudent.gmall.search.entity.Goods;
import com.atstudent.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * service-search远程服务接口
 * @Author 薛有朋
 * @CreatDate 2025/3/13 21:37
 **/
@RestController
@RequestMapping(value = "/api/inner/search")
public class GoodsRpcController {

    @Autowired
    private GoodsBizService goodsBizService;

    /**
     * 向es中保存商品数据
     * @Author 薛有朋
     * @Date 2025/3/15 19:49
     * 因为是feign远程调用，且参数是一个实体类，所以用PostMapping
     **/
    @PostMapping(value = "/saveGoods")
    public Result saveGoods(@RequestBody Goods goods){
        goodsBizService.saveGoods(goods);
        return Result.ok();
    }

    /**
     * 根据skuId删除es中保存的商品数据
     * @Author 薛有朋
     * @Date 2025/3/15 19:49
     **/
    @DeleteMapping(value = "/deleteGoods/{id}")
    public Result deleteGoods(@PathVariable(value = "id") Long skuId){
        goodsBizService.deleteGoods(skuId);
        return Result.ok();
    }

    /**
     * 在es中搜索商品数据
     * @Author 薛有朋
     * @Date 2025/3/15 21:48
     **/
    @PostMapping(value = "/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParamDTO searchParamDTO){
        SearchResponseVo searchResponseVo = goodsBizService.search(searchParamDTO);
        return Result.ok(searchResponseVo);
    }

    /**
     * 更新es索引库中的热度分
     * @Author 薛有朋
     * @Date 2025/3/23 13:43
     **/
    @PutMapping(value = "/updateHotScore/{skuId}/{hotScore}")
    public Result updateHotScore(
            @PathVariable(value = "skuId") Long skuId ,
            @PathVariable(value = "hotScore") Long hotScore){
        goodsBizService.updateHotScore(skuId,hotScore);
        return Result.ok();
    }
}
